<template>
    <div class="checkbox" @click="change">
        <i v-if="checked" class="iconfont icon-checked"></i>
        <i v-else class="iconfont icon-unchecked"></i>
        <span v-if="$slots.default">
            <slot />
        </span>
    </div>
</template>
  <script>
export default {
    name: 'Checkbox',
}
</script>
<script setup>
import { computed } from 'vue';

const props = defineProps({
    modelValue: {
        type: Boolean,
        default: false
    }
})

const emit = defineEmits ()
const change = () => {
    emit('update:modelValue', !props.modelValue)
}

const checked = computed(() => {
    return props.modelValue
})
</script>
<style scoped lang="scss">
.checkbox {
    display: inline-block;
    margin-right: 2px;

    .icon-checked {
        color: $mainColor;

        ~span {
            color: $mainColor;
        }
    }

    i {
        position: relative;
        top: 1px;
    }

    span {
        margin-left: 2px;
    }
}
</style>